import Vue from "vue";
import VueRouter from "vue-router";
const Login = () => import("@/views/Login/Login.vue");
const Home = () => import("../views/Home/Home.vue");
const myNotice = () => import("../views/Home/myNotice/myNotice");
const Health = () => import("../views/Home/Health/Health");
const Holiday = () => import("../views/Home/Holiday/Holiday");
const tell = () => import("../views/Home/tell/tell");
const User = () => import("../views/Home/User/User");

Vue.use(VueRouter);

const routes = [
  {
    path: "*",
    redirect: "/",
  },
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    component: Home,
    children: [
      {
        path: "/myNotice",
        component: myNotice,
      },
      {
        path: "/health",
        component: Health,
      },
      {
        path: "/holiday",
        component: Holiday,
      },
      {
        path: "/tell",
        component: tell,
      },
      {
        path: "/user",
        component: User,
      },
    ],
  },
  {
    path: "/login",
    name: "Login",
    component: Login,
  },
];

const router = new VueRouter({
  routes,
});

//设置路由拦截
router.beforeEach((to, from, next) => {
  if (to.path === "/") {
    localStorage.getItem("token") ? next() : next("/login");
  }
  next();
});
export default router;
